<template>
<div>
  <el-button style="position: absolute;left: 330px"
             type="primary" plain @click="dialogVisible=true">查看退货用户</el-button>
  <br>
  <br>
  <br>
  <el-dialog
    title="提示"
    :visible.sync="dialogVisible"
    width="80%"
    :before-close="handleClose">
    <el-table
      :data="finddate"
      border
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="uname"
        label="退货受理人"
        width="180">
      </el-table-column>
      <el-table-column
        prop="kuaidi"
        label="快递名称">
      </el-table-column>
      <el-table-column
        prop="parcelid"
        label="快递单编号">
      </el-table-column>
      <el-table-column
        prop="fname"
        label="退货人">
      </el-table-column>
      <el-table-column
        prop="returntime" :formatter="dateFormat"
        label="退货时间">
      </el-table-column>
      <el-table-column
        prop="remark"
        label="退货原因">
      </el-table-column>
      <el-table-column
        prop="state"
        label="退货状态">
        <template slot-scope="scope">
          <span v-if="scope.row.state == 5">已退货</span>
        </template>
      </el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
  </el-dialog>
  <el-table
    :data="tableData"
    border
    style="width: 100%">
    <el-table-column
      prop="id"
      label="编号"
      width="180">
    </el-table-column>
    <el-table-column
      prop="uname"
      label="退货受理人"
      width="180">
    </el-table-column>
    <el-table-column
      prop="kuaidi"
      label="快递名称">
    </el-table-column>
    <el-table-column
      prop="parcelid"
      label="快递单编号">
    </el-table-column>
    <el-table-column
      prop="fname"
      label="退货人">
    </el-table-column>
    <el-table-column
      prop="returntime" :formatter="dateFormat"
      label="退货时间">
    </el-table-column>
    <el-table-column
      prop="remark"
      label="退货原因">
    </el-table-column>
    <el-table-column
      prop="state"
      label="退货状态">
      <template slot-scope="scope">
        <span v-if="scope.row.state == 4">退货审核中</span>
      </template>
    </el-table-column>
    <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button @click="dialogFormVisible=true;returnsupd=scope.row"
                   type="danger" icon="el-icon-delete" size="small">退货</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-dialog title="退货" :visible.sync="dialogFormVisible">
    <el-form :model="returnsupd">
      <el-form-item label="退货处理人" :label-width="formLabelWidth">
        <el-select v-model="returnsupd.user" placeholder="请选择退货处理人">
          <el-option v-for="item in finduser" :label="item.name" :key="item.uid" :value="item.uid"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="退货原因"  :label-width="formLabelWidth">
        <el-input type="textarea" v-model="returnsupd.remark" disabled="disabled"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="dialogFormVisible = false;returns()">确 定</el-button>
    </div>
  </el-dialog>

  <el-pagination
    small
    layout="total,prev, pager, next"
    :page-size="pageSize"
    :total="total" @current-change="page">
  </el-pagination>
</div>
</template>

<script>
export default {
  name: "Salesreturn",
  data(){
   return{
     total: 0,
     pageSize: 6,
     tableData: [],
     dialogFormVisible:false,
     formLabelWidth: '120px',
     returnsupd:{},
     finduser:[],
     dialogVisible:false,
     finddate:[]
   }
  },
  created() {
   this.find()
    this.userfind()

  },
  methods:{
    find(){
      this.$http.post("backservice/forder/returnpage?pageNum=0&pageSize=" + this.pageSize).then(response => {
        console.log(response.userList)
        this.tableData = response.userList
        this.total = response.TotalNum
      })
    },
    page(currentPage) {
      this.$http.post('backservice/forder/returnpage?&pageNum=' + (currentPage - 1) + '&pageSize=' + this.pageSize)
        .then(response => {
          this.tableData = response.userList
        })
    },
    dateFormat(row, column, cellValue, index) {
      const daterc = row[column.property]
      if (daterc != null) {
        var date = new Date(daterc);
        var year = date.getFullYear();
        /* 在日期格式中，月份是从0开始，11结束，因此要加0
         * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
         * */
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
        // 拼接
        return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
      }
    },
    returns(){
      let id=this.returnsupd.id;
      let user=this.returnsupd.user
      let  fid=this.returnsupd.f_order
      this.$http.post('backservice/forder/returnupd',{user:user,id:id}).then(data=>{
        if (data>0){
          alert("退货成功")
          this.$http.post('backservice/forder/upd',{id:fid})
          this.find()
          this.returntable()
        }else {
          alert("退货失败")
        }
      })
    },
    userfind(){
      this.$http.post('backservice/user/finduser1').then(data=>{
        this.finduser=data
      })
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    returntable(){
      this.$http.post('backservice/forder/findreturns').then(data=>{
        console.log(data)
        this.finddate=data
      })
    }
  }
}
</script>

<style scoped>

</style>
